home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / nocz12.zip / NOCZ.ASM < prev    next >
Assembly Source File  |  1989-10-13  |  3KB  |  120 lines

  1.     Name nocz
  2.     Title    Control Z stripping filter.
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that removes all occurrances
  7.     of the ASCII character 26 (^Z) from its output stream.
  8.     It will optionally accept a filename from which to read
  9.     input.  All output goes to the     standard output device
  10.     unless redirected.
  11.  
  12.     Examples:
  13.         nocz abc.txt    read input from abc.txt,
  14.                 output goes to screen.
  15.         nocz abc.txt >abcnew.txt
  16.                 read input from abc.txt,
  17.                 output goes to abcnew.txt.
  18.         nocz <abc.txt >abcnew.txt
  19.                 same as previous example
  20. /
  21. ;===================================================================
  22. code    segment    public
  23. ;===================================================================
  24. ;
  25. ;    command line is at 80h of psp - first byte is length
  26. ;
  27.     ORG    80h
  28. parmsize    DB    ?
  29. parm        DB    7fh DUP (?)
  30. ;
  31. ; .com starts at 100h - but must jump around any data area
  32. ;
  33.     ORG    100h            ; com file starts here
  34.     ASSUME    CS:code,DS:code,ES:code
  35. nocz:
  36.     jmp    clear
  37. ;===================================================================
  38. ;
  39. ; data area for .com programs
  40. ;
  41. handle    DW    0h            ; assume standard input
  42. bufsiz    EQU    256
  43. ;
  44. ;===================================================================
  45. clear:
  46. ;
  47. ; start of actual code is here (clear)
  48. ;
  49.     mov    AH,30h        ; get dos version
  50.     int    21h
  51.     cmp    AL,2        ; must be at least 2.0
  52.     jb    oops
  53. ;
  54. ; release uneeded memory
  55. ;
  56.     mov    BX,offset buffer[512]    ; 256 byte buffer
  57.     mov    SP,BX            ; + 256 byte local stack
  58.     mov    CX,4
  59.     sar    BX,CL
  60.     inc    BX        ; paragraphs needed = end/16 + 1
  61.     mov    AH,4AH        ; SETBLOCK
  62.     int    21h
  63. ;
  64. ; now figure out which file to read from - parm line or standard input
  65. ;
  66.     cmp    parmsize,0h    ; if zero, no parm
  67.     jz    again        ; assume standard input
  68. ;
  69. ; parm length is not zero - assume the parm is a file name.  If not
  70. ; found, quit.
  71. ;
  72.     mov    AL,parmsize    ; get size of parm
  73.     xor    AH,AH        ; zero out top part of accum.
  74.     mov    SI,AX        ; use length as a pointer into the dta
  75.     mov    [SI]+parm,0h    ; to tack on a zero byte (asciiz).
  76. ;
  77. ; now try to open the file
  78. ;
  79.     mov    DX,offset parm+1    ; address of 'filename'
  80.     mov    AL,0h        ; open for read only
  81.     mov    AH,3dh        ; dos open function
  82.     int    21h        ; invoke function
  83.     jc    oops        ; open error - quit
  84.     mov    handle,AX    ; save file handle
  85. again:
  86.     mov    BX,handle    ; read from standard input or file
  87.     mov    CX,bufsiz    ; # of characters to read
  88.     mov    DX,offset buffer
  89.     mov    AH,3fh        ; dos read function
  90.     int    21h        ; invoke function
  91.     jc    oops        ; error!
  92.     cmp    AX,0h        ; if zero, end of file
  93.     jz    oops
  94. ;
  95.     mov    CX,AX        ; CX contains # characters read
  96.     mov    SI,offset buffer; DS:SI is the "input" pointer
  97.     mov    DI,SI        ; ES:DI is the "output" pointer
  98. loop1:
  99.     lodsb            ; get a character from buffer
  100.     cmp    AL,26        ; if ^Z then skip
  101.     je    eatit
  102.     stosb            ; put back into buffer
  103. eatit:
  104.     loop    loop1        ; and repeat for entire buffer
  105. ;
  106.     mov    CX,DI        ; Now calculate the ouput character
  107.     sub    CX,offset buffer; count
  108.     mov    BX,1h        ; standard output device
  109.     mov    AH,40h        ; dos write function
  110.     int    21h        ; invoke dos function
  111.  
  112.     jmp    short again    ; repeat until end of file or error
  113. oops:
  114.     int    20h        ; return to dos
  115.  
  116. buffer    LABEL    NEAR
  117.  
  118. code    ENDS
  119.     END    nocz
  120.